﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KaiXin.BLL;
using KaiXin.DTO.Tycoon;
using System.Threading;
using KaiXin.BLL.Interface;
using KaiXin.BLL.Tycoon;

namespace Tycoon
{
    class Program
    {
        static void Main(string[] args)
        {

            IKXTycoon ty = new KXTycoon();
            ShowMenus();
            string code = Console.ReadLine();
            while (code!="exit")
            {
                switch (code)
                {
                  
                    case "goods":
                        Console.WriteLine("系统正在读取数据......");
                        List<Goods> list = ty.GetTOP10(g=>g.CurrentPrice>800000);
                        Console.Clear();
                        ShowMenus();
                        Console.WriteLine();
                        foreach (var item in list)
                        {
                            Console.WriteLine(string.Format("{0}    {1}     现价：{3}   跌了{2}%    最高价格为:{4}", item.Class.Name, item.Name, item.Prec, Format(item.CurrentPrice), Format(item.MaxPrice)));
                        }
                        
                        break;
                    case "clear":
                        Console.Clear();
                        ShowMenus();
                        break;
                    default:
                        Console.WriteLine("无效命令");
                        break;
                }
                code = Console.ReadLine();
            }
           
        }


        static void ShowMenus()
        {
            Console.WriteLine("********** 小猫专用 ************");
            Console.WriteLine();
            Console.WriteLine("goods    返回跌幅前10名(去除小商贩)");
            Console.WriteLine("clear    清空屏幕");
            Console.WriteLine("exit     退出程序");
            Console.WriteLine("********************************");
        }

        static string Format(long price)
        {
            string bigUnit = string.Empty;
            if (price / (100000000 * 10000.0) >= 1)
            {
                bigUnit = "万亿";
                return (price / (100000000 * 10000.0)).ToString() + bigUnit;
            }
            else if (price / (10000 * 10000.0) >= 1)
            {
                bigUnit = "亿";
                return (price / (10000 * 10000.0)).ToString() + bigUnit;
            }
            else if (price / 10000.0 >= 1)
            {
                bigUnit = "万";
                return (price /  10000.0).ToString() + bigUnit;
            }
            return price.ToString();
        }
       
    }
}
